package gui;

import java.awt.event.ActionEvent;
import java.util.Observable;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JOptionPane;

@SuppressWarnings("serial")
public class QuitControl extends Observable {
	private JButton myQuitButton;
	private String[] myOptions = {"Quit & Save", 
			"Quit Without Saving", "Cancel"};
	public QuitControl() {
		myQuitButton = new JButton( 
		new AbstractAction("Quit") {
			@Override
			public void actionPerformed(ActionEvent e) {
				int selection = 					
					JOptionPane.showOptionDialog(null, 
							"Quit Smart Peer Review", 
							"Quit", 
							JOptionPane.OK_CANCEL_OPTION, 
							JOptionPane.QUESTION_MESSAGE, 
							null, 
							myOptions, 
							0);
				switch (selection) {
				case 0:
					setChanged();
					notifyObservers(State.SAVE);
					System.exit(selection);
					break;
				case 1:
					System.exit(selection);
					break;
				default:
					// cancel do nothing
					break;
				}
			}
		});
	}

	public JButton getButton() {
		return myQuitButton;
	}
}
